// components/heart/index
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    stature:{
      type:Number,
    },
    weight:{
      type:Number,
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    circumstances:'',//腰围
    targetnum:'',//胸围
    minmotion:'',//臀围
    maxmotion:'',//手臂
    userheith:'',//身高
    userweight:'',//手腕
    RiskL:'',//小腿
    BMInum:'',//大腿
    jiaohuan:'',//脚踝
    imgsrc:'../../img/mdi.jpeg',
    flag:0,//模式切换
    sexflag:0,//性别
    textList:['黄金比例的身材主要能够让身材看起来显得更加美感，协调度也是比较好的，让整个人的身材看起来显得更加匀称，在医学上又被称作黄金分割'],
    show:false,
    sexList:[{name:'对比',value:'0',checked:true},{name:'最佳',value:'1',checked:false}],
    newsexList:[{name:'男性',value:'0',checked:true,},{name:'女性',value:'1',}],
  },

  methods: {
    sexrChange(e){
      const {sexList} = this.data;
      let num='0';
      for (let i = 0, len = sexList.length; i < len; ++i) {
        sexList[i].checked=sexList[i].value === e.detail.value
        num=e.detail.value
      }
      this.setData({
        sexList,
        flag:parseInt(num),
        userheith:'',circumstances:'',targetnum:'',minmotion:'',maxmotion:'',BMInum:'',RiskL:'',jiaohuan:''
      })

      this.triggerEvent('setopints',parseInt(num))
    },
    newsexrChange(e){
      const {newsexList} = this.data;
      let num='0';
      for (let i = 0, len = newsexList.length; i < len; ++i) {
        newsexList[i].checked=newsexList[i].value === e.detail.value
        num=e.detail.value
      }
      console.log(num)
      this.setData({
        newsexList,
        sexflag:parseInt(num),
        userheith:'',circumstances:'',targetnum:'',minmotion:'',maxmotion:'',BMInum:'',RiskL:'',jiaohuan:''
      })
    },
    inputwidth(e){
      if((/^[0-9]+$/).test(e.detail.value)){
        this.setData({
          userheith:e.detail.value
        })
        return        
      }
      this.setData({
        userheith:''
      })
    },
    inputwidth1(e){
      if((/^[0-9]+$/).test(e.detail.value)){
        this.setData({
          userweight:e.detail.value
        })
        return        
      }
      this.setData({
        userweight:''
      })
    },
    inputwidth2(e){
      if((/^[0-9]+$/).test(e.detail.value)){
        this.setData({
          RiskL:e.detail.value
        })
        return        
      }
      this.setData({
        RiskL:''
      })
    },

    inputgetdata(e){
      if((/^[0-9]+$/).test(e.detail.value)){
        this.setData({
          circumstances:e.detail.value
        })
        return        
      }
      this.setData({
        circumstances:''
      })
    },
    inputgetdata1(e){
      if((/^[0-9]+$/).test(e.detail.value)){
        this.setData({
          targetnum:e.detail.value
        })
        return        
      }
      this.setData({
        targetnum:''
      })
    },
    inputgetdata2(e){
      if((/^[0-9]+$/).test(e.detail.value)){
        this.setData({
          maxmotion:e.detail.value
        })
        return        
      }
      this.setData({
        maxmotion:''
      })
    },
    inputgetdata3(e){
      if((/^[0-9]+$/).test(e.detail.value)){
        this.setData({
          minmotion:e.detail.value
        })
        return        
      }
      this.setData({
        minmotion:''
      })
    },
    inputgetdata4(e){
      console.log(7890)

      if((/^[0-9]+$/).test(e.detail.value)){
        this.setData({
          BMInum:e.detail.value
        })
        return        
      }
      this.setData({
        BMInum:''
      })
    },
    inputgetdata5(e){
      if((/^[0-9]+$/).test(e.detail.value)){
        this.setData({
          RiskL:e.detail.value
        })
        return        
      }
      this.setData({
        RiskL:''
      })
    },
    inputgetdata6(e){
      if((/^[0-9]+$/).test(e.detail.value)){
        this.setData({
          jiaohuan:e.detail.value
        })
        return        
      }
      this.setData({
        jiaohuan:''
      })
    },
    inputgetdata7(e){
      if((/^[0-9]+$/).test(e.detail.value)){
        this.setData({
          userheith:e.detail.value
        })
        return        
      }
      this.setData({
        userheith:''
      })
    },


    positionChange(e){
      const {positionList} = this.data;
      let num='0';
      for (let i = 0, len = positionList.length; i < len; ++i) {
        positionList[i].checked=positionList[i].value === e.detail.value
        num=e.detail.value
      }
      this.setData({
        positionList,
        positionnum:num,
        flag:num
      })

    },
    sertap(){
      wx.showToast({
        title: ' 单位（CM）',
        icon:'none',
        duration:2000,
        mask:true
      })
    },
    click(){
      // flag:0,//模式切换
      // sexflag:0,//性别

      const {flag,userheith,sexflag,circumstances,targetnum,maxmotion,minmotion,BMInum,jiaohuan,RiskL} = this.data
      let newarr=[circumstances,targetnum,minmotion,maxmotion,BMInum,RiskL,jiaohuan]//用户输入的数据
      let arr=[];
      if(flag==0&&sexflag==0){
      let manarr=[circumstances,targetnum,minmotion]
        for(let i=0;i<manarr.length;i++){//男士计算
          if(manarr[i]==''){
            wx.showToast({
              title: '请输入可靠数据！',
              icon:'error',
              duration:2000,
              mask:true
            })
            return
          }
        }
        arr=setadd({userheith,sexflag})//最佳标准数据
        this.triggerEvent('setarrdata',{manarr,arr,sexflag})    
      }else{
          arr=setadd({userheith,sexflag}) 
          console.log(arr)
          this.triggerEvent('setarrdata',{manarr:newarr,arr,sexflag})
        }

    },
    newclick(){      
        this.setData({
          userheith:'',circumstances:'',targetnum:'',minmotion:'',maxmotion:'',BMInum:'',RiskL:'',jiaohuan:''
        })
    },
  }
}) 

// 计算
function setadd(params) {
  let {userheith,sexflag}=params;
  let arr=[];
  if(!sexflag){
    // 男生标准三围是：胸围=身高*0.48， 腰围=身高*0.47， 臀围=身高*0.51。
    let circumstances=parseInt(userheith*0.47)
    let targetnum=parseInt(userheith*0.48)
    let minmotion=parseInt(userheith*0.51)
    arr=[circumstances,targetnum,minmotion]
  }else{
    let circumstances=parseInt(userheith*0.37)
    let targetnum=parseInt(userheith*0.53)
    let minmotion=parseInt(userheith*0.54)
    let maxmotion=parseInt(userheith*0.15)
    let BMInum=parseInt(userheith*0.26+7.8)
    let RiskL=parseInt(userheith*0.18)
    let jiaohuan=parseInt(userheith*0.12)
    arr=[circumstances,targetnum,minmotion,maxmotion,BMInum,RiskL,jiaohuan]
  }
  return arr

//腰围=身高*0.37(+-5%)
//胸围=身高*0.53 上下3厘米为标准范围。
//臀围=身高*0.54 
//手臂=身高*0.15
//大腿=身高*0.26＋7.8
//小腿=身高*0.18
//腿颈=身高*0.12
//     circumstances:'',//腰围
//     targetnum:'',//胸围
//     minmotion:'',//臀围
//     maxmotion:'',//手臂
//     BMInum:'',//大腿
//     RiskL:'',//小腿
//     jiaohuan:'',//脚踝
// circumstances:'',//腰围
// targetnum:'',//胸围
// minmotion:'',//臀围
// 男生标准三围是：胸围=身高*0.48， 腰围=身高*0.47， 臀围=身高*0.51。
// 男生健美三围标准是：胸围=身高*0.61，腰围=身高*0.42，臀围=身高*0.64。
// 标准臀围（cm）= 身高（cm）×0.54
// 标准胸围（cm）= 身高（cm）×0.53
// 标准腰围（cm）= 身高（cm）×0.42或 身高（cm）÷2-11（cm）

}
